<div class="contact">
    <div class="forms fl">
        <h2>Kontakt forma</h2>
        <form id="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
            <table class="general" cellpadding="0" cellspacing="0" width="100%">
                <tbody>

                    <tr>
                        <td width="300">
                            <label>ime i prezime</label>
                            <span class="input">
                                <input class="inputBig" type="text" name="name" value="" />
                            </span>
                        </td>
                        <td>&nbsp;</td>

                    </tr>
                    <tr>
                        <td>
                            <label>email adresa</label>
                            <span class="input">
                                <input class="inputBig r" type="text" name="email" value="" />
                            </span>
                        </td>

                        <td>
                            <span id="r_email" style="display:none;">obavezno popuniti</span>
                            <span id="r_format_email" style="display:none;">neispravna el.adresa</span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>poruka</label>
                            <span class="textarea">
                                <textarea class="inputBig r" name="msg" rows="3" cols="1"></textarea>

                            </span>
                        </td>
                        <td>
                            <span id="r_msg" style="display:none;">obavezno popuniti</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <a href="javascript:;" class="send" id="send">pošalji</a>
                        </td>

                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <div class="notif error" style="display: none;">
                                Poruka nije poslata, pokušajte ponovo.
                            </div>
                            <div class="notif success" style="display: none;">
                                Poruka uspešno poslata.
                            </div>

                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div class="map">
        <h2>Neki naslov nemam pojma</h2>
        <p>ovde moze neki tekst whatever</p>

    </div>
</div>
<script type="text/javascript">
    $(document).ready( function(){
        
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        $("#send").click(function(){
            var allOk = true;
            $(".r").each(function(){
                if($(this).val().length <= 0)
                {
                    allOk = false;
                    $('#r_format_' + $(this).attr('name')).hide();
                    $('#r_' + $(this).attr('name')).show();
                }
                else
                {
                    if($(this).attr('name') == 'email' && reg.test($(this).val()) == false)
                    {
                        allOk = false;
                        $('#r_' + $(this).attr('name')).hide();
                        $('#r_format_' + $(this).attr('name')).show();
                    }
                    else
                    {
                        $('#r_' + $(this).attr('name')).hide();
                        $('#r_format_' + $(this).attr('name')).hide();
                    }
                }
            });
            
            if(allOk)
            {
                //Submit form
                $.post('/kontakt/submit',
                        {'name' : $("input[type='name']").val(),
                         'email': $("input[type='email']").val(),
                         'msg'  : $("input[type='msg']").val()},
                        function(data){
                            if(data){
                                $('.error').hide();
                                $('.success').show();
                                //Clear fields
                                $('input, textarea').each(function(){
                                    $(this).val('');
                                });
                            }else{
                                $('.success').hide();
                                $('.error').show();
                            }
                        }
                );
            }
        });
    });
</script>

